<template>
	<view>
		<view v-if="orders" style="padding-bottom: 150rpx;">
			<u-card v-for="item in orders.orderRemarks" box-shadow="10rpx 10rpx 10rpx #c8c9cc" :show-head="false">
				<view class="" slot="body">
					<span>{{item.remark_content}}</span>
				</view>
				<view class="" slot="foot" style="display: flex;justify-content: space-between;">
					<view>{{item.employe_name}}</view>
					<view>{{item.step_name}}</view>
					<view>{{$u.timeFormat(item.add_datetime, 'mm月dd日 hh:MM')}}</view>
				</view>
			</u-card>
		</view>
		<view style="position: fixed;width: 100%;bottom: 0rpx;padding: 0;z-index: 999;">
			<u-button type="primary" @click="show=true">添加备注</u-button>
		</view>
		<u-popup v-model="show" mode="top" >
			<view style="padding: 0 30rpx;" > 
				<u-form :model="form" ref="uForm" label-position="top">
					<u-form-item label="备注内容"><u-input v-model="form.remark_content" type="textarea" border height="300" /></u-form-item>
					<u-form-item>
						<u-button type="primary" @click="submit">添加</u-button>
					</u-form-item>
				</u-form>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				orders: null,
				form: {
					remark_content: ''
				},
				rules: {
					remark_content: [{
						required: true,
						message: '请输入备注内容',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		onLoad(options) {
			if (options.data) {
				this.orders = JSON.parse(decodeURIComponent(options.data));
			}
		},
		methods: {
			submit() {
				var that = this;
				var form = that.form;
				form.orders_id = this.orders.orders_id;
				that.$http.post('/orderRemark/insert', form, (res) => {
					if (res.data.success) {
						that.show=false;
						that.getOrderInfo();
						that.$refs.uToast.show({
							title: '添加成功',
							type: "success"
						});
						uni.$emit("getOrdersInfo", that.data);
					} else {
						that.$refs.myModal.show('登录失败', res.data.result.message);
					}
				});
			},
			getOrderInfo() {
				var that = this;
				that.$http.get('/orders/queryById?orders_id=' + this.orders.orders_id, {}, (res) => {
					if (res.data.success) {
						that.orders = res.data.result;
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style>

</style>